package com.liuh.edu.common;

import org.apache.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @note 全局异常配置
 * @author liuh
 * @date 2018年7月6日 上午11:06:07
 */
@ControllerAdvice
public class ExceptionAdvice {

	public static final Logger logger = Logger.getLogger(ExceptionAdvice.class);
	
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Exception.class)
    public String handleException(Exception e,Model model) {
        logger.error("服务运行异常,"+e.getMessage());
        model.addAttribute("error","服务运行异常,"+e.getMessage());
        return "errors/500";
    }
}
